import { DomUtils } from '../utils/DomUtilsMin';


/**
 * 百家号 (https://baijiahao.baidu.com) 移动端网页美化
 * 
 * 测试网页:
 * - https://baijiahao.baidu.com/s?id=1792769656680429991
 */
export class BaiJiaHao {

    static hostname = 'baijiahao.baidu.com';

    main() {
        DomUtils.hide([
            // 顶部header
            '#headDeflectorContainer',
            // 听文章
            '#ttsGuide',
            // 文章图片下方的打开APP按钮
            ...document.querySelectorAll('.openImg'),
            // 评论输入框和按钮的bar
            '#wise-invoke-interact-bar',
            // 打开APP悬浮按钮
            '#bdrainrwDragButton',
            // 推荐区域
            document.querySelector('#commentModule').parentElement.nextElementSibling,
            // 评论输入框
            '._3PMGWEixIuYY-UKDKo0eer',
            // 打开APP查看评论按钮
            '.I93A3I9G2BRddV73LoQ37',
            // 举报/反馈 按钮
            '.horizontal '
        ]);
        DomUtils.observe('#page_wrapper > .other', ['childList'], { childList: true }, ({ observer, target }) => {
            // 隐藏打开APP悬浮按钮
            const bdrainrwDragButton = target.querySelector('#bdrainrwDragButton');
            if (bdrainrwDragButton) {
                bdrainrwDragButton.style.display = 'none';
            }
            
            // 隐藏推荐区域
            const comments = document.querySelector('#commentModule');
            if (comments) {
                DomUtils.hide(comments.parentElement.nextElementSibling, 'scale');
            }

            // 文章展开
            document.querySelector('.iconArrow')?.click()
            DomUtils.hide('.oPadding')
        });
        // 隐藏评论输入框
        DomUtils.observe(document.body, ['childList'], { childList: true }, () => {
            const el = document.querySelector('#wise-invoke-interact-bar')
            DomUtils.hide(el, 'scale');
        });
    }

}